project(MediaPlayer)
cmake_minimum_required(VERSION 3.22)

if (NOT PF)
    set(PF "HOST")
    MESSAGE(STATUS "Unspecified Platform, Use " ${PF} ", \nUsage: \"cmake -D PF=HOST RK\"")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

if (PF STREQUAL "HOST")
    set(PLATFORM_NAME "host linux")
    set(CMAKE_C_COMPILER "gcc")
    set(CMAKE_CXX_COMPILER "g++")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -D HOST")
elseif(PF STREQUAL "RK")
    set(PLATFORM_NAME "rockchip")
    set(CMAKE_C_COMPILER "/opt/rk3328/bin/aarch64-buildroot-linux-gnu-gcc")
    set(CMAKE_CXX_COMPILER "/opt/rk3328/bin/aarch64-buildroot-linux-gnu-g++")
    set(CMAKE_FIND_ROOT_PATH "/opt/rk3328/aarch64-buildroot-linux-gnu/sysroot")
    set(FFMPEG_INSTALL_PATH "/home/cdl/work/ffmpeg/rk/install")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -D RK -I${CMAKE_FIND_ROOT_PATH}/usr/include/libdrm -I${FFMPEG_INSTALL_PATH}/include")
else()
    MESSAGE(FATAL_ERROR "Please specify the platform. \nUsage: \"cmake -D PF=HOST RK\"")
endif()

set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})

MESSAGE(STATUS "Current Platform: " ${PLATFORM_NAME})
MESSAGE(STATUS "CC Name: " ${CMAKE_C_COMPILER})
MESSAGE(STATUS "CXX Name: " ${CMAKE_CXX_COMPILER})
MESSAGE(STATUS "Install Prefix: " ${CMAKE_INSTALL_PREFIX})
MESSAGE(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
MESSAGE(STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})

set(MEDIA_PLAY_SRC )
aux_source_directory(. MEDIA_PLAY_SRC)

include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/spdlog/include)

#不会将警告当作错误处理
add_definitions(-fpermissive)

if (PF STREQUAL "HOST")
	list(REMOVE_ITEM MEDIA_PLAY_SRC "./DRMVideoSink.cpp") #HOST去掉DRMVideoSink.cpp
	link_libraries("pthread" "avformat" "avcodec" "avutil" "swresample" "swscale" "avfilter" "asound" "SDL2")
elseif (PF STREQUAL "RK")
	list(REMOVE_ITEM MEDIA_PLAY_SRC "./SDLVideoSink.cpp")
	link_directories(${FFMPEG_INSTALL_PATH}/lib)
	link_libraries("pthread" "avformat" "avcodec" "avutil" "swresample" "swscale" "avfilter" "asound" "drm")
else()
    MESSAGE(FATAL_ERROR "Please specify the platform. \nUsage: \"cmake -D PF=HOST RK\"")
endif()

#MESSAGE(STATUS "MEDIA_PLAY_SRC: " ${MEDIA_PLAY_SRC})

add_executable(MediaPlayer ${MEDIA_PLAY_SRC})
